from flask import Flask, render_template, request

app = Flask(__name__)


@app.route('/nav', methods=["get", "post"])
def nav():
    if request.method == "GET":
        return render_template("index.html")
    else:
        return render_template("greeting_card.html")


@app.route('/greeting_card', methods=["get", "post"])
def card():
    return render_template("greeting_card.html")


@app.route('/<int:id>', methods=['GET', 'POST'])
@app.route('/', methods=('GET', 'POST'))
def index(id=None):
    global name, login
    # 然后发起一个post请求
    if request.method == 'POST':
        # 判断请求的账户和密码，如果判断成功，那么跳到下一个页面去
        if request.form.get('account') == 'admin' and request.form.get('pwd') == 'admin':
            login = 'success'
            name = 'admin'
            return render_template('index.html', name=name, login=login)
        else:
            login = 'fail'
            return render_template('fail.html')
    return render_template('login.html')

@app.route('/empty',methods=('GET', 'POST'))
def empty():
    if request.method == "GET":
        return render_template('empty.html')
    else:
        return render_template('index.html')


if __name__ == '__main__':
    app.run()
